﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.Configuration;

namespace cwtrock.dao.impl
{
    /// <summary>
    /// 数据访问抽象基础类
    /// </summary>
   public  class DbHelperSQL
    {
        public SqlConnection con = null;
        private string sqlconconfig = "server=TENMANZHIWU\\SQLEXPRESS;uid=whs;pwd=123456;database=cwtrock";
       
       

        public DbHelperSQL()
        {
        }

        public SqlConnection GetCon()
        {
            try
            {
                //转义字符 // 
                con = new SqlConnection(sqlconconfig);
                con.Open();
                return con;
            }// end block try()
            catch (Exception e)
            {
                con = null;
                return con;
            }// end block catch()

        }
       
       
        /// <summary>
        /// 执行查询语句，返回DataSet
        /// </summary>
        /// <param name="SQLString">查询语句</param>
        /// <returns>DataSet</returns>
        public  DataSet Query(string SQLString)
        {
            con = GetCon();
            {
                DataSet ds = new DataSet();
                try
                {
                    SqlDataAdapter command = new SqlDataAdapter(SQLString, con);
                    command.Fill(ds, "ds");
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    throw new Exception(ex.Message);
                }
                return ds;
            }
        }
        public  DataSet Query(string SQLString, int Times)
        {
            con = GetCon();
            {
                DataSet ds = new DataSet();
                try
                {
                    //connection.Open();
                    //SqlDataAdapter command = new SqlDataAdapter(SQLString, connection);
                    //command.SelectCommand.CommandTimeout = Times;
                    //command.Fill(ds, "ds");
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    throw new Exception(ex.Message);
                }
                return ds;
            }
        }

        
       
    }
}
